from typing import List


class Solution:
    def subSort(self, array: List[int]) -> List[int]:
        if len(array) < 2:
            return [-1, -1]

        stack, i2 = [], 0
        start = True
        max_val = float("-inf")
        for i, n in enumerate(array):
            # 计算开始位置
            while stack and n < stack[-1]:
                stack.pop()
                start = False
            if start:
                stack.append(n)

            # 计算结束位置
            if n >= max_val:
                max_val = n
            else:
                i2 = i

        return [len(stack), i2] if len(stack) < i2 else [-1, -1]


if __name__ == "__main__":
    # [3,9]
    print(Solution().subSort([1, 2, 4, 7, 10, 11, 7, 12, 6, 7, 16, 18, 19]))

    # [-1,-1]
    print(Solution().subSort([]))

    # [-1,-1]
    print(Solution().subSort([1, 3, 5, 7, 9]))

    # [2,4]
    print(Solution().subSort([1, 3, 9, 7, 5]))

    # [52,612]
    print(Solution().subSort(
        [-616, -608, -597, -597, -597, -592, -591, -590, -590, -589, -586, -586, -582, -582, -581, -576, -568, -568,
         -567, -566, -564, -562, -561, -554, -551, -549, -549, -547, -547, -546, -544, -542, -540, -537, -536, -535,
         -534, -534, -534, -534, -526, -526, -525, -523, -518, -515, -515, -507, -505, -504, -499, -499, -211, -298,
         -269, -289, -229, -403, -214, -462, -337, -228, -249, -391, -333, -297, -271, -264, -220, -300, -385, -413,
         -466, -263, -313, -427, -346, -455, -305, -295, -461, -383, -331, -493, -294, -214, -349, -444, -388, -483,
         -234, -488, -321, -430, -346, -359, -305, -339, -326, -459, -274, -454, -428, -230, -272, -430, -286, -325,
         -474, -497, -483, -376, -196, -281, -432, -223, -372, -286, -431, -480, -467, -389, -212, -467, -492, -448,
         -483, -489, -199, -241, -262, -252, -365, -424, -372, -359, -345, -371, -265, -367, -289, -437, -377, -493,
         -397, -391, -238, -428, -258, -440, -459, -201, -347, -268, -332, -394, -496, -448, -367, -308, -297, -428,
         -437, -274, -210, -403, -263, -320, -422, -480, -422, -461, -286, -391, -479, -438, -244, -261, -397, -348,
         -276, -330, -418, -423, -489, -237, -237, -408, -202, -442, -462, -446, -272, -306, -293, -199, -332, -400,
         -196, -180, -171, -170, -169, -164, -158, -154, -153, -146, -146, -144, -141, -136, -136, -134, -125, -125,
         -122, -121, -120, -120, -118, -114, -112, -111, -105, -101, -92, -84, -84, -83, -83, -78, -76, -76, -72, -72,
         -71, -70, -69, -69, -69, -66, -66, -64, -61, -60, -58, -56, -55, -53, -52, -52, -49, -49, -47, -44, -42, -39,
         -36, -25, -21, -20, -20, -19, -17, -15, -14, -13, -11, -10, -9, -8, -7, -4, 0, 6, 8, 10, 11, 14, 14, 14, 14,
         15, 16, 17, 20, 31, 32, 35, 36, 37, 41, 42, 42, 42, 44, 45, 52, 52, 53, 53, 56, 58, 60, 62, 63, 64, 65, 67, 67,
         69, 69, 70, 73, 74, 76, 76, 81, 84, 85, 86, 86, 87, 90, 96, 101, 101, 102, 106, 108, 111, 112, 112, 113, 113,
         116, 117, 118, 119, 122, 123, 127, 128, 131, 132, 133, 134, 134, 136, 145, 146, 147, 151, 151, 154, 158, 159,
         161, 162, 162, 162, 162, 166, 167, 168, 168, 168, 169, 170, 171, 175, 176, 181, 183, 183, 184, 185, 187, 192,
         194, 194, 195, 199, 200, 201, 202, 202, 205, 206, 209, 210, 214, 214, 215, 215, 220, 222, 223, 226, 227, 231,
         232, 234, 236, 237, 240, 242, 244, 244, 245, 246, 249, 252, 254, 256, 256, 257, 259, 260, 261, 267, 267, 267,
         269, 270, 275, 275, 276, 277, 278, 280, 282, 285, 285, 287, 288, 289, 289, 290, 292, 292, 294, 295, 297, 297,
         305, 306, 307, 308, 308, 309, 310, 312, 314, 315, 315, 319, 320, 322, 322, 326, 326, 326, 328, 334, 334, 334,
         334, 335, 343, 343, 344, 347, 349, 350, 351, 353, 355, 356, 359, 360, 366, 367, 368, 368, 371, 374, 374, 382,
         383, 384, 386, 386, 387, 389, 390, 392, 397, 403, 404, 406, 406, 407, 416, 419, 419, 422, 422, 423, 425, 425,
         427, 431, 433, 434, 435, 436, 436, 438, 442, 443, 444, 444, 447, 447, 447, 450, 451, 454, 454, 454, 462, 468,
         469, 470, 472, 473, 477, 478, 478, 481, 482, 484, 485, 486, 492, 493, 494, 496, 497, 499, 499, 502, 503, 504,
         506, 507, 508, 516, 518, 522, 525, 527, 532, 533, 536, 536, 538, 544, 545, 548, 549, 549, 550, 551, 551, 552,
         553, 553, 553, 555, 557, 558, 558, 558, 562, 563, 563, 563, 564, 568, 573, 578, 578, 579, 588, 591, 593, 593,
         594, 596, 597, 598, 600, 601, 601, 605, 605, 607, 608, 611, 611, 612, 613, 616, 617]))
